<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>calculate</title>
	</head>
	<style type="text/css">
		select {
			width: 30px;
			height: 20px;
			text-align: center;
			-moz-appearance: none; /*firefox*/
			-webkit-appearance: none; /*safari and Chrome*/
		 }
	</style>
	<body>
		
		<input type="text" id="contentOne" />
		<select id="select">
			<option id="plus" >+</option>
			<option id="minus" >-</option>
			<option id="times" >*</option>
			<option id="divide" >/</option>
		</select>
		<input type="text" id="contentTwo" /> 
		<button type="button" id="result">=</button>
		<input type="text" id="num" />
		<!-- <button type="button" id="test">t</button> -->
	</body>
	<script type="text/javascript">
		// document.getElementById("test").onclick = f;
		document.getElementById("result").onclick = check;

		// function f(){
		// 	var i = 1;
		// 	console.log(1);
		// 	console.log(typeof(i))
		//  //需要用string全等...
		// 	if(typeof(i) == "number"){
		// 		console.log("I");
		// 	} 
			
		// }

		function check(){
			var c1 = document.getElementById("contentOne").value;
			var c2 = document.getElementById("contentTwo").value;
			if(c1.length == 0 || c2.length == 0 || c1 == null || c2 == null)
			{
				alert("输入不能为空");
			}else if(!isNaN(c1) && !isNaN(c2)){
				var arr = document.getElementById("select");
				var index = arr.selectedIndex;
				var sum;
				switch(arr[index].value){
					case "+":
						sum = parseInt(c1) + parseInt(c2);
						document.getElementById("num").value = sum;
						break;
					case "-":
						sum = parseInt(c1) - parseInt(c2);
						document.getElementById("num").value = sum;
						break;
				    case "*":
				    	sum = parseInt(c1) * parseInt(c2);
				    	document.getElementById("num").value = sum;
				    	break;
					case "/":
						sum = parseInt(c1) / parseInt(c2);
						document.getElementById("num").value = sum;
						break;	
				}
				
			}else{
				alert("不要输入非法字符");
			}
			
		}
	</script>
</html>
